/*******************************************************************************
 * 
 * Copyright:
 * 
 * License:
 * 
 * Authors: SALMON Charles
 * 
 ******************************************************************************/

/*******************************************************************************
 * 
 ******************************************************************************/

/**
 * The GUI definition of the bip admin view
 */
qx.Class.define("bip.adminview.AdminView", {
	extend : qx.ui.container.Composite,
	
	type: "singleton",
	
	/*
	 * ****************************************************************************
	 * CONSTRUCTOR
	 * ****************************************************************************
	 */

	construct : function() {
		this.base(arguments);

		// Configure layout
		var layout = new qx.ui.layout.VBox;
		layout.setSeparator("separator-vertical");
		this.setLayout(layout);

	  // Commands & Menu Bar
		this.__makeCommands();
		this.__buildToolBar();

	},

	/*
	 * ****************************************************************************
	 * PROPERTIES
	 * ****************************************************************************
	 */

	properties : {

	},

	/*
	 * ****************************************************************************
	 * MEMBERS
	 * ****************************************************************************
	 */

	members : {
		
		// ------------------------------------------------------------------------
		// CONSTRUCTOR HELPERS
		// ------------------------------------------------------------------------
		
		__makeCommands : function() {
			/*this._cmdObjectSummary = new qx.ui.core.Command("Ctrl+O");
			this._cmdObjectSummary.addListener("execute",
					this.__getObjectSummary, this);

			this._cmdRunSample = new qx.ui.core.Command("F5");
			this._cmdRunSample.addListener("execute", this.runSample, this);

			this._cmdPrevSample = new qx.ui.core.Command("Ctrl+Left");
			this._cmdPrevSample.addListener("execute", this.playPrev, this);

			this._cmdNextSample = new qx.ui.core.Command("Ctrl+Right");
			this._cmdNextSample.addListener("execute", this.playNext, this);

			this._cmdSampleInOwnWindow = new qx.ui.core.Command("Ctrl+N");
			this._cmdSampleInOwnWindow.addListener("execute",
					this.__openWindow, this);

			this._cmdDisposeSample = new qx.ui.core.Command("Ctrl+D");
			this._cmdDisposeSample.addListener("execute", this.__disposeSample,
					this);

			this._cmdNamespacePollution = new qx.ui.core.Command("Ctrl+P");
			this._cmdNamespacePollution.addListener("execute",
					this.__showPollution, this);*/
		},
		
		__buildToolBar : function() {
			var bar = bip.Application.getToolBar();
			
			// IMPORT SURVEY
      // -----------------------------------------------------
			var fileUploadHttpServlet = "$[FILE-UPLOAD-HTTP-URI]$";
	    var form = new uploadwidget.UploadForm('uploadFrm',fileUploadHttpServlet);
	    form.setParameter('rm','upload');
	    form.setLayout(new qx.ui.layout.Basic);
	    form.addListener('completed',function(e) {
	    	var response = form.getIframeTextContent();
	      form.clear();
	      alert(response);
	    },this);

			var file = new uploadwidget.UploadButton('uploadfile', 'Import Survey',null);
			file.setAppearance("toolbar-button");
			file.setIconPosition("left");
			file.setToolTipText("Manage topics");
	    form.add(file, {left:0,top:0});
	    file.addListener('changeFileName',function(e){
	      if(e.getData()!='') {
	          form.send();
	      }
	    });
	    bar.add(form);
	    
	    // USER VIEW
      // -----------------------------------------------------

      var userViewMenu = new qx.ui.menu.Menu;
      
      bip.userview.UserPages.getInstance().iteratePages(function(pageName,page){
      	var button = new qx.ui.menu.Button(pageName);
      	button.addListener("execute", function(e) {
  	    	bip.Application.getInstance().load(pageName);
  	    });
        userViewMenu.add(button);
    	},this);
      
      var userViewButton = new qx.ui.toolbar.MenuButton(this.tr("UserView"), null, userViewMenu);
      userViewButton.setToolTipText("UserView pages");
      bar.add(userViewButton);
      
      // AUTHOR VIEW
      // -----------------------------------------------------

      var authorViewMenu = new qx.ui.menu.Menu;

      bip.authorview.AuthorPages.getInstance().iteratePages(function(pageName,page){
      	var button = new qx.ui.menu.Button(pageName);
      	button.addListener("execute", function(e) {
  	    	bip.Application.getInstance().load(pageName);
  	    });
      	authorViewMenu.add(button);
    	},this);

      var authorViewButton = new qx.ui.toolbar.MenuButton(this.tr("AuthorView"), null, authorViewMenu);
      authorViewButton.setToolTipText("AuthorView pages");
      bar.add(authorViewButton);
			
			
		}

	},

	/*
	 * ****************************************************************************
	 * DESTRUCTOR
	 * ****************************************************************************
	 */

	destruct : function() {
		this._disposeObjects("__winNewTopic","__winNewQuestion","__winSearchTopic","__winManageTopics","__winFillSurvey",
				"__questionService");
	}
});
